/**
 *  all request 
 */
import axios from 'axios'
import { Notification } from 'element-ui'
import storage from '@/plugins/localStorage'
import router from '../router'
import Crypto from "@/utils/crypto";

import { url, autograph } from "./url"
export default class requests {
  static async login(param) { //登录
    try {
      console.log('param', param)
      const res = await axios({
        method: 'post',
        url: url + 'login',
        data: param
      });
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('login请求报错:' + e)
      return null
    }
  }
  static async loginOut(id) { //登出
    try {
      const res = await axios.get(url + 'logout/' + id);
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('login请求报错:' + e)
      return null
    }
  }
  static async fetchStationNameList(param) { //水站名称下拉列表
    console.log(param);
    try {
      const res = await axios({
        method: 'post',
        url: url + 'station/water-station/nameList',
        data: param
      });
      // const res = await axios.POST(url + 'station/water-station/nameList')
      if (res.status === 200) {
        console.log(res);
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchStationMonMap() { //水站地图
    try {
      const res = await axios.get(url + 'station/water-station/map')
      if (res.status === 200 && res.data.message === "success") {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchStationNewMonMap() { //新水站地图
    try {
      const res = await axios.get(url + 'station/monitor-system/realdatas')
      if (res.status === 200 && res.data.message === "success") {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchStationMonList() { //水站列表table
    try {
      const res = await axios.get(url + 'station/monitor-system/datas')
      if (res.status === 200 && res.data.message === "success") {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchExcessStations() { //获取超标站点列表
    try {
      const res = await axios.get(url + 'station/water-station/excessStations')
      if (res.status === 200 && res.data.message === "success") {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchFaultDevices() { //获取故障设备列表
    try {
      const res = await axios.get(url + 'station/water-station/faultDevices')
      console.log('fetchFaultDevices data:', res)
      if (res.status === 200 && res.data.message === "success") {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchDispatchSelect() { //调度条件下拉列表
    try {
      const res = await axios.get(url + 'job/dispatch')
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchVehicleNum() { //车辆编号下拉列表
    try {
      const res = await axios.get(url + 'job/vehicle')
      if (res.status === 200) {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postMonitorDispatch(param) { //提交调度条件form
    try {
      const res = await axios({
        method: 'post',
        url: url + 'job/dispatch',
        data: param
      });
      console.log('postMonitorDispatch data:', res)
      // debugger
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchMonitorDispatchList(params) { //获取监测调度列表
    try {
      const res = await axios({
        method: 'get',
        url: url + 'job/dispatch/list',
        params
      });
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async checkContentPlotForm(param) { //检验 维护维修内容填写
    try {
      const res = await axios({
        method: 'post',
        url: url + 'job/operate/check',
        data: param
      });
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }

  }
  static async postContentPlotForm(param) { //提交维护维修内容填写
    try {
      const res = await axios({
        method: 'post',
        url: url + 'job/operate',
        data: param
      });
      // debugger
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchContentPlotList(param) { //获取维护维修 历史列表
    try {
      const res = await axios({
        method: 'get',
        url: url + 'job/operate/list',
        params: param
      });
      if (res.status === 200) {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchStationConsumable(station) { //获取维护维修 历史列表
    try {
      const res = await axios({
        method: 'post',
        url: url + 'property/consumable?station=' + station
      });
      if (res.status === 200) {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchHistoryDataChart(param) { //获取历史数据图表
    try {
      const res = await axios({
        method: 'post',
        url: url + 'station/water-data/form',
        data: {
          waterstation: param.waterstation,
          starttime: param.starttime + " 00:00:00",
          lasttime: param.lasttime + " 23:59:59",
          isExcel: param.isExcel,
        }
      });
      if (res.status === 200 && res.data.message === "success") {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchHistoryDataList(param) { //获取历史数据列表table
    const payload = {
      waterstation: param.waterstation,
      starttime: param.starttime + " 00:00:00",
      lasttime: param.lasttime + " 23:59:59",
      isExcel: param.isExcel,
      pageSize: param.pageSize,
      pageNum: param.pageNum,
    }
    try {
      const res = await axios({
        method: 'post',
        url: url + 'station/water-data/list',
        data: payload
      });
      if (res.status === 200 && res.data.message === "success") {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postHistoryDataListExcel(param) { //历史数据 导出
    try {
      const res = await axios({
        method: 'post',
        url: url + 'station/water-data/excel',
        responseType: "blob",
        data: {
          stations: param.stations,
          starttime: param.starttime,
          lasttime: param.lasttime,
          isExcel: "yes",
        }
      });
      if (res.status === 200) {
        const content = res.data
        const blob = new Blob([content], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" })
        const filesName = '历史数据' + param.starttime + ' - ' + param.lasttime + ".xlsx"
        if (window.navigator && window.navigator.msSaveOrOpenBlob) {
          window.navigator.msSaveOrOpenBlob(content, filesName);
        } else {
          if ('download' in document.createElement('a')) {
            const elink = document.createElement('a')
            elink.download = filesName
            elink.style.display = 'none'
            elink.href = URL.createObjectURL(blob)
            document.body.appendChild(elink)
            elink.click()
            URL.revokeObjectURL(elink.href)
            document.body.removeChild(elink)
          } else {
            Notification.error({
              title: '错误',
              message: '网络有误！请稍后重试',
              duration: 3000
            })
          }
        }
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postQualityEvaluationChart(param) { //获取 所有水站 水质量环境评价图表
    try {
      const res = await axios({
        method: 'post',
        url: url + 'station/water-data/rate',
        data: param
        // {
        //   startTime: param.startTime + " 00:00:00",
        //   endTime: param.endTime + " 23:59:59",
        // }
      });
      if (res.status === 200 && res.data.message === "success") {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postQualityEvaDetailChart(param) { //获取 单个水站 水质量环境评价图表
    try {
      const res = await axios({
        method: 'post',
        url: url + 'station/water-data/rate/detail',
        data: param
      });
      if (res.status === 200 && res.data.message === "success") {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postQualityEvaDetailList(param) { //获取 单个水站 单个因子的 超标/达标 的列表数据
    try {
      const res = await axios({
        method: 'post',
        url: url + 'station/water-data/exceedAndStandard',
        data: param
      });
      if (res.status === 200 && res.data.message === "success") {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postQualityEvaluationLine(param) { //获取水质量环境评价线形图
    try {
      const res = await axios({
        method: 'post',
        url: url + 'station/water-data/period',
        data: {
          starttime: param.starttime,
          lasttime: param.lasttime,
        }
      });
      if (res.status === 200 && res.data.message === "success") {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postQualityContrast(param) { //获取水质量环境对比数据
    try {
      const res = await axios({
        method: 'post',
        url: url + 'strategy/compare',
        data: param
      });
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postFactorRankChart(param) {  //获取水质量环境排名 因子排名
    try {
      const res = await axios({
        method: 'post',
        url: url + 'station/water-data/gridRanking',
        data: param
      });
      if (res.status === 200 && res.data.message === "success") {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postRankAnalysisChart(param) { //获取水质量环境排名 排名统计分析
    try {
      const res = await axios({
        method: 'post',
        url: url + 'station/water-data/gridRanking/analysis',
        data: param
      });
      // debugger
      if (res.status === 200 && res.data.message === "success") {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchReportFormsList(params) { //辅助决策 报告报表 周日月报
    try {
      const res = await axios({
        method: 'get',
        url: url + 'report',
        params
      });
      if (res.status === 200 && res.data.message === "success") {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postPolluteEventList(param) { //污染溯源 污染列表
    try {
      const res = await axios({
        method: 'get',
        url: url + 'pollutionTrace',
        params: param
      });
      if (res.status === 200) {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postPolluteEventUpload(formData) { //污染溯源 污染上传
    try {
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data',
        }
      }
      const res = await axios.post(url + 'pollutionTrace', formData, config)
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postResearchAnalysis(param) { //研判分析
    try {
      const res = await axios({
        method: 'post',
        url: url + 'mobile/monitoring-data/analysisData',
        data: {
          waterstation: param.waterstation,
          vehicle: param.vehicle || null,
          starttime: param.starttime,
          lasttime: param.lasttime,
          isExcel: param.isExcel,
        }
      });
      if (res.data.message !== 'success') {
        Notification.warning({
          title: '警告',
          message: res.data.info,
          duration: 10000
        })
        return []
      }
      if (res.status === 200) {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postResearchAnalysisExcel(param) { //研判分析 导出表格
    try {
      const res = await axios({
        method: 'post',
        url: url + 'mobile/monitoring-data/analysisData',
        responseType: "blob",
        data: {
          waterstation: param.waterstation,
          vehicle: param.vehicle || null,
          starttime: param.starttime,
          lasttime: param.lasttime,
          isExcel: param.isExcel,
        }
      });
      if (res.status === 200) {
        const content = res.data
        const blob = new Blob([content], { type: "application/vnd.ms-excel" })
        // debugger
        if ('download' in document.createElement('a')) {
          const elink = document.createElement('a')
          elink.download = '研判分析数据表'
          elink.style.display = 'none'
          elink.href = URL.createObjectURL(blob)
          document.body.appendChild(elink)
          elink.click()
          URL.revokeObjectURL(elink.href)
          document.body.removeChild(elink)
        } else {
          Notification.error({
            title: '错误',
            message: '网络有误！请稍后重试',
            duration: 3000
          })
        }
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postMobileMonitorData(param) { //移动监测 实时概览
    try {
      const res = await axios({
        method: 'get',
        url: url + 'mobile/routing',
        params: param
      });
      if (res.status === 200) {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async postMobileMonitorLineInput(param) { //移动监测 线路信息录入
    try {
      const res = await axios({
        method: 'post',
        url: url + 'mobile/routing',
        data: param
      });
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async postMobileMonitorInput(formData) { //移动监测 点位信息录入
    try {
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data',
        }
      }
      const res = await axios.post(url + 'mobile/routing/point', formData, config)
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postDailyEventAdminList(param) { //日常管理 事件列表
    try {
      const res = await axios({
        method: 'get',
        url: url + 'job/event',
        params: param
      });
      if (res.status === 200) {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async postDailyEventAdminUpload(formData) { //日常管理 事件上传
    try {
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data',
        }
      }
      const res = await axios.post(url + 'job/event', formData, config)
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postDailyLogAdminList(param) { //日常管理 日志列表
    try {
      const res = await axios({
        method: 'get',
        url: url + 'job/sys-log',
        params: param
      });
      if (res.status === 200) {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async getDailyTaskList(param) { //日常管理 任务列表
    try {
      const res = await axios({
        method: 'get',
        url: url + 'task',
        params: param
      });
      if (res.status === 200) {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchWaterStationUsers() { //水域管理 水站管理员列表
    try {
      const res = await axios.get(url + 'station/file/stationuser')
      if (res.status === 200 && res.data.message === "success") {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchWaterStationPollutant() { //水域管理 相关排污企业列表
    try {
      const res = await axios.get(url + 'station/file/pollutant')
      if (res.status === 200 && res.data.message === "success") {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchWaterOperationuser() { //水域管理 获取运维人员列表
    try {
      const res = await axios.get(url + 'station/file/operationuser')
      if (res.status === 200 && res.data.message === "success") {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async postWaterStationAdded(param) { //水域管理 站点新增
    try {
      const res = await axios({
        method: 'post',
        url: url + 'station/file/add',
        data: param
      });
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchMonitorSystemSel() { //水域管理 水站档案 监测系统编号下拉菜单
    try {
      const res = await axios({
        method: 'get',
        url: url + 'station/file/monitorSystems',
      });
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchWaterStationList() { //水域管理 获取列表
    try {
      const res = await axios.get(url + 'station/file/stationData')
      if (res.status === 200 && res.data.message === "success") {
        return res.data.info
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchWaterPollutionSourceType() { //水域管理 污染源行业类型
    try {
      const res = await axios.get(url + 'station/file/sourceType')
      if (res.status === 200 && res.data.message === "success") {
        return res.data.info
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async postWaterPollutionAdded(param) { //水域管理 企业档案新增
    try {
      const res = await axios({
        method: 'post',
        url: url + 'station/file/addpollutant',
        data: param
      });
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async postWaterPollutionSupplement(param) { //水域管理 企业档案补录
    try {
      const res = await axios({
        method: 'post',
        url: url + 'station/pollutant-source',
        data: param
      });
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchWaterPollutionList(param) { //水域管理 企业档案列表
    try {
      const res = await axios.post(url + 'station/file/pollutantData', {
        pollutantName: param.pollutantName || null,
        pageSize: param.pageSize,
        pageNum: param.pageNum,
      })
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchAssetAdminList(param) { //资产管理 库存管理列表
    try {
      const res = await axios.post(url + 'repertory/in-storage/inventoryStatistics', { stationName: param.stationName || null })
      if (res.status === 200 && res.data.message === "success") {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchAssetStationManager() { //资产管理 获取水站关联管理员
    try {
      const res = await axios.get(url + 'repertory/in-storage/stationUser')
      if (res.status === 200 && res.data.message === "success") {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchAssetConsumable() { //资产管理 获取备件耗材名称
    try {
      const res = await axios.get(url + 'repertory/in-storage/consumable')
      if (res.status === 200 && res.data.message === "success") {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async postAssetAdminEntry(param) { //资产管理 资产录入
    try {
      const res = await axios({
        method: 'post',
        url: url + 'repertory/in-storage/addassets',
        data: param
      });
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchUserList(params) { //用户管理 获取获取用户列表
    try {
      const res = await axios.get(url + 'system/user', { params })
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchUserDetail(account) { //用户管理 获取详情
    try {
      const res = await axios.get(url + 'system/user/' + account)
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async postSystemUserAdd(formData) { //用户管理 新增用户
    try {
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data',
        }
      }
      const res = await axios.post(url + 'system/user', formData, config)
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async putUpdatePassword(params) { //用户管理 修改密码
    try {
      const res = await axios({
        method: 'put',
        url: url + 'system/user/password',
        data: params
      });
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async putForgetPassword(data) { //用户管理 忘记密码
    try {
      const res = await axios({
        method: 'put',
        url: url + 'system/user/forgetPassword',
        data
      });
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async getStreetMessage() { //获取所有街道信息
    try {
      const res = await axios({
        method: 'get',
        url: url + 'station/water-station/streetMessage',
      });
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async postUserRegister(formData) { //用户管理 用户申请账号 注册
    try {
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data',
        }
      }
      const res = await axios.post(url + 'register', formData, config)
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchAuditList() { //系统管理 审核列表
    try {
      const res = await axios.get(url + 'system/user/reviewUser')
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async postAuditUser(data) { //系统管理 审核操作
    try {
      const res = await axios.post(url + 'system/user/reviewUser', data, { 'Content-Type': 'multipart/form-data' })
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchTechnicalList(keyword) { //信息公开 获取技术档案
    try {
      const res = await axios.get(url + 'system/file/technical', { search: keyword })
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchLawsRegulaList(params) { //信息公开 获取法律法规列表
    try {
      const res = await axios.get(url + 'system/file/statute', { params })
      // debugger
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchStationInstrument() { //文件管理 获得文件类型和仪器列表（水站）
    try {
      const res = await axios.get(url + 'system/file')
      if (res.status === 200 && res.data.message === 'success') {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async postSystemFiles(formData) { //文件管理 文件上传
    try {
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data',
        }
      }
      const res = await axios.post(url + 'system/file', formData, config)
      // debugger
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchRuntimeRecord(param) { //仪器有效运行记录
    try {
      const res = await axios({
        method: 'get',
        url: url + 'job/runtime-record',
        params: param
      });
      // debugger
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchCarAdminList(data) { //车辆管理 列表
    try {
      const res = await axios({
        method: 'post',
        url: url + 'repertory/in-storage/vehicleMessage',
        data: {
          vehicle: data.vehicle || null,
          pageSize: data.pageSize,
          pageNum: data.pageNum,
        }
      });
      // debugger
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async postCarAdminAdd(data) { //车辆管理 新增车辆
    try {
      const res = await axios({
        method: 'post',
        url: url + 'repertory/in-storage/vehicle',
        data
      });
      // debugger
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchWarningTypes() { //预警管理 获取预警类型
    try {
      const res = await axios({
        method: 'get',
        url: url + 'warning/type',
      });
      // debugger
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      return null
    }
  }
  static async fetchWarningAdminList(data) { //预警管理 列表
    try {
      const res = await axios({
        method: 'post',
        url: url + 'warning/list',
        data: {
          waterStation: data.waterStation || null,
          warningType: data.warningType || null,
          starttime: data.starttime || null,
          lasttime: data.lasttime || null,
          pageSize: data.pageSize,
          pageNum: data.pageNum,
          warningStatus: data.warningStatus === '' ? null : data.warningStatus == 0 ? 0 : data.warningStatus
        },
      });
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      // console.log('请求报错:' + e.response);
      return null
    }
  }
  static async fetchWarningDetail(data) { //预警管理 预警详情
    try {
      const res = await axios({
        method: 'post',
        url: url + 'warning',
        data
      });
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      return null
    }
  }
  static async updateWarningAdmin(formData) { //预警管理 处理预警 
    try {
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data',
        }
      }
      console.log('formData', formData)
      const res = await axios.post(url + 'warning/update', formData, config)
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async updateWarningAdminBatch(formData) { //预警管理 批量处理预警 
    try {
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data',
        }
      }
      const res = await axios.post(url + 'warning/update/batch', formData, config)
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async responseWarningAdmin(data) { //预警管理 响应预警
    try {
      const res = await axios.post(url + 'warning/handle?id=' + data.id)
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchRealTimeWarning() { //监控概览 实时预警面板
    try {
      const res = await axios.get(url + 'station/water-station/abnormal')
      console.log('fetchRealTimeWarning data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }

  static async postFeedback(data) { //提交意见反馈
    try {
      const res = await axios.post(url + 'app', data)
      console.log('postFeedback data:', res)
      // debugger
      if (res.status === 200 && res.data.message === 'success') {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async getFeedbackList(params) { //获取意见反馈列表
    try {
      const res = await axios.get(url + 'app/feedBack', { params })
      // debugger
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async downloadApp() { //下载app
    try {
      const res = await axios({
        method: 'get',
        url: url + 'table/download',
        responseType: "blob",
      });
      console.log('downloadApp data:', res)
      // debugger
      if (res.status === 200) {
        const content = res.data
        const blob = new Blob([content], { type: "application/apk" })
        if ('download' in document.createElement('a')) {
          const elink = document.createElement('a')
          elink.download = 'app'
          elink.style.display = 'none'
          elink.href = URL.createObjectURL(blob)
          document.body.appendChild(elink)
          elink.click()
          URL.revokeObjectURL(elink.href)
          document.body.removeChild(elink)
        } else {
          Notification.error({
            title: '错误',
            message: '网络有误！请稍后重试',
            duration: 3000
          })
        }
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postRetrieveData(data) { //历史数据 找回数据
    try {
      const res = await axios.post(url + 'station/water-data/request', {
        lasttime: data.lasttime,
        starttime: data.starttime,
        waterstation: data.waterstation,
      })
      console.log('postRetrieveData data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }

  static async fetchResourceList() { //获取所有菜单
    try {
      const res = await axios.get(url + 'system/resource')
      console.log('fetchResourceList data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async updateResourceList(resource) { //提交 修改菜单
    try {
      const res = await axios.post(url + 'system/resource', resource)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async putResource(data) { //提交 修改单个菜单
    try {
      const res = await axios({
        url: url + 'system/resource',
        method: "put",
        data: {
          "id": data.id,
          "isApp": 1,
          "isDeleted": 0,
          "name": data.name,
          "orderNum": data.orderNum,
          "parentId": data.parentId,
          "type": data.type,
          "url": data.url
        }
      })
      if (res.status === 200 && res.data.message === 'success') {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async addResource(data) { //新增一个菜单
    try {
      const res = await axios({
        url: url + 'system/resource/add',
        method: "post",
        data: {
          "id": data.id,
          "isApp": 1,
          "isDeleted": 0,
          "name": data.name,
          "orderNum": data.orderNum,
          "parentId": null,
          "type": 0,
          "url": data.url
        }
      })
      console.log('addResource data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async deleteResource(resourceId) { //删除一个菜单
    try {
      const res = await axios({
        url: url + 'system/resource?resourceId=' + resourceId,
        method: "delete",
      })
      console.log('deleteResource data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchRolseList() { //获取所有角色
    try {
      const res = await axios.get(url + 'system/role')
      console.log('fetchRolseList data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchRolseMenusList(id) { //获取所有角色的菜单
    try {
      const res = await axios.get(url + 'system/role/menus?roleId=' + id)
      console.log('fetchRolseMenusList data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async updateRolseMenus(data) { //获取所有角色的菜单
    try {
      const res = await axios.post(url + 'system/role', data)
      console.log('updateRolseMenus data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async getTransportList(data) { //获取废液转运 列表
    try {
      const res = await axios.post(url + 'wastetransfer/wastetransfer/lists', data)
      console.log('getTransportList data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async insertTransportInput(formData) { //废液转运 新增
    try {
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data',
        }
      }
      const res = await axios.post(url + 'wastetransfer/wastetransfer/insert', formData, config)
      console.log('insertTransportInput data:', res)
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async exportTransportExcel(param) { //废液转运 导出
    try {
      const res = await axios({
        method: 'post',
        url: url + 'wastetransfer/wastetransfer/lists',
        responseType: "blob",
        data: {
          waterstation: param.waterstation,
          starttime: param.starttime,
          lasttime: param.lasttime,
          isExcel: param.isExcel,
        }
      });
      console.log('exportTransportExcel data:', res)
      if (res.status === 200) {
        const content = res.data
        const blob = new Blob([content], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" })
        // debugger
        if ('download' in document.createElement('a')) {
          const elink = document.createElement('a')
          elink.download = '废液转运' + param.starttime + ' - ' + param.lasttime
          elink.style.display = 'none'
          elink.href = URL.createObjectURL(blob)
          document.body.appendChild(elink)
          elink.click()
          URL.revokeObjectURL(elink.href)
          document.body.removeChild(elink)
        } else {
          Notification.error({
            title: '错误',
            message: '网络有误！请稍后重试',
            duration: 3000
          })
        }
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async getEquipmentList(data) { //获取设备管理 列表
    try {
      const res = await axios.get(url + 'job/operate/device?search=' + data.waterstation)
      console.log('getEquipmentList data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async getOperationList(payload) { //获取应急运维列表管理 列表
    const params = Object.assign({}, payload, {
      startTime: payload.startTime + " 00:00:00",
      endTime: payload.endTime + " 23:59:59"
    })
    try {
      const res = await axios.post(url + 'job/operate-record/page', params)
      console.log('getOperationList data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async addOperationRecord(formData) { //新增应急运维列表管理 记录
    try {
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data',
        }
      }
      const res = await axios.post(url + 'job/operate-record/problem', formData, config)
      console.log('addOperationRecord data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async solveOperationRecord(formData) { //解决应急运维列表管理 记录
    try {
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data',
        }
      }
      const res = await axios.post(url + 'job/operate-record/solution', formData, config)
      console.log('solveOperationRecord data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async updateOperationRecord(data) { //修改应急运维列表管理 记录
    try {
      const res = await axios.post(url + 'job/operate-record/edit', data)
      console.log('updateOperationRecord data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async getDailyOperationList(payload) { //获取日常运维列表管理 列表
    const params = Object.assign({}, payload, {
      startTime: payload.startTime + " 00:00:00",
      endTime: payload.endTime + " 23:59:59"
    })
    try {
      const res = await axios.post(url + 'job/operate/page', params)
      console.log('getDailyOperationList data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async updateDailyOperation(formData) { //修改 日常运维
    try {
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data',
        }
      }
      const res = await axios.post(url + 'job/operate', formData, config)
      console.log('updateDailyOperation data:', res)
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  // static async addOperationRecord(formData) { //新增应急运维列表管理 记录
  //   try {
  //     let config = {
  //       headers: {
  //         'Content-Type': 'multipart/form-data',
  //       }
  //     }
  //     const res = await axios.post(url + 'job/operate-record/problem', formData, config)
  //     console.log('addOperationRecord data:', res)
  //     if(res.status === 200 && res.data.message === 'success') {
  //       return res.data
  //     }
  //     return null
  //   } catch (e) {
  //     console.log('请求报错:' + e)
  //     return null
  //   }
  // }
  // 
  // static async updateOperationRecord(data) { //修改应急运维列表管理 记录
  //   try {
  //     const res = await axios.post(url + 'job/operate-record/edit', data)
  //     console.log('updateOperationRecord data:', res)
  //     if(res.status === 200 && res.data.message === 'success') {
  //       return res.data
  //     }
  //     return null
  //   } catch (e) {
  //     console.log('请求报错:' + e)
  //     return null
  //   }
  // }
  static async setOperationCycle(payload) { //设置运维周期提醒
    try {
      const res = await axios.put(url + 'task/remind', payload)
      console.log('setOperationCycle data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async getUserOnline() { //获取在线人数
    try {
      const res = await axios.get(url + 'online')
      console.log('getUserOnline data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async postSiteSelection(payload) { //选择 查看的站点
    try {
      const res = await axios.post(url + 'station/water-station/siteSelection', { stations: payload })
      console.log('postSiteSelection data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async updateWarnPcInfome(flag) { //修改预警提醒方式
    try {
      const res = await axios.post(url + 'warning/pcinforme', { type: flag })
      console.log('updateWarnPcInfome data:', res)
      if (res.status === 200 && res.data.message === 'success') {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async putUserBindStation(payload) { //修改用户绑定的水站
    try {
      const res = await axios.put(url + 'system/user-station', payload)
      console.log('putUserBindStation data:', res)
      if (res.status === 200) {
        return res.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchAllCandoStation() { //获取用户能操作的所有水站
    console.log('fetchAllCandoStation data:')
    try {
      const res = await axios.get(url + 'station/water-station/all')
      console.log('fetchAllCandoStation data:', res)
      if (res.status === 200) {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
  static async fetchStationsInfo() { //用户选择下的站点信息
    try {
      const res = await axios.get(url + 'station/water-station/stations')
      console.log('fetchStationsInfo data:', res)
      if (res.status === 200) {
        return res.data.data
      }
      return null
    } catch (e) {
      console.log('请求报错:' + e)
      return null
    }
  }
}

//  REQUEST 请求异常拦截
axios.interceptors.request.use(config => {
  console.log('autograph', autograph)
  let tep = Date.now()
  let atoken = Crypto.encrypt(tep + '/' + autograph)
  //==========  所有请求之前都要执行的操作  ==============
  let token = null
  console.log(new Date(Date.now()))
  if (sessionStorage.getItem('token')) {
    token = sessionStorage.getItem('token')
  } else if (config.url.indexOf("login") === -1) {
    console.log("未获取到token")
  }
  config.headers.atoken = atoken
  config.headers.timestamp = tep
  if (token) {
    config.headers.token = token
  }
  console.log('所有请求之前都要执行的操作config', config)
  return config;
}, err => {
  //==================  错误处理  ====================
  console.log('request错误处理err:', err)
  Notification.error({
    title: '网络错误',
    message: '请求超时！请稍后重试',
    duration: 10000
  })
  return Promise.resolve(err);
})
//  RESPONSE 响应异常拦截
axios.interceptors.response.use(data => {
  //==============  所有请求完成后都要执行的操作  ==================
  console.log('请求完成后的的返回', data)
  if (data.status === "fail") {
    Notification.error({
      title: '错误',
      message: '服务器错误！请联系管理员',
      duration: 10000
    })
  }
  return data;
}, err => {
  //==============  错误处理  ====================
  console.log('response错误处理err:', err)
  // debugger;
  if (err.response.status === 401) {
    Notification.warning({
      title: '错误',
      message: '登录过期，请重新登录！',
      duration: 3000
    })
    console.log('登录过期')
    storage.reload()
    router.push('/login')
    return Promise.reject(err)
  }
  if (err.response.status === 400) {
    Notification.error({
      title: '请稍后再试',
      message: '服务器繁忙,请稍后再试',
      duration: 10000
    })
    return Promise.reject(err)
  }
  Notification.error({
    title: '错误',
    message: '服务器错误！请联系管理员',
    duration: 10000
  })
  return Promise.resolve(err);
})